﻿/*
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <unistd.h>
#include <pthread.h>

#include "poolsocket.h"

void* start_routine(void* arg)
{
	int ret;
	int timeout = 3;
	int connfd = (int)arg;

	unsigned char* out = NULL;
	int outlen = 0;

	while (1)
	{

		//LABLE:
			//3.服务器端，接收报文；1
		ret = sckServer_rev(connfd, timeout, &out, outlen);
		if (ret == Sck_ErrPeerClosed)
		{
			//5.检测到，对（方）端关闭，则关闭本端；
			//sckServer_close(connfd);
			printf("----------------------ErrPeerClosed 关闭服务器\n");
			//return NULL;
			break;
		}
		else if (ret == Sck_ErrTimeOut)
		{
			printf("---服务器检测到客户端发送数据-超时 \n");

			//6.在这里可以不return，直接跳回去，重新接收一下；
			//return NULL;
			//goto LABLE;
			continue;
		}
		else if (ret != 0)
		{
			printf("未知错误\n");
			//return NULL;
			break;
		}

		//7.处理数据；-----回射（服务器）；
		printf("==========客户端发送了：%s\n", out);

		//2.服务器端，发送报文；
		ret = sckServer_send(connfd, timeout, out, outlen);
		if (ret == Sck_ErrPeerClosed)
		{
			//8.检测到，对（方）端关闭，则关闭本端；
			//sckServer_close(connfd);
			printf("---ErrPeerClosed \n");
			//return NULL;
			break;
		}
		else if (ret == Sck_ErrTimeOut)
		{
			//9.一般在并发访问量较高时，才会出现这样的情况；
			printf("---服务器检测到本端发送数据-超时 \n");
			//return NULL;
			continue;
		}
		else if (ret != 0)
		{
			printf("未知错误\n");
			//return NULL;
			break;
		}
	}

	//10.检测到，对（方）端关闭，则关闭本端；
	sckServer_close(connfd);

	return NULL;
}

int main345(void)
{
	int listenfd;
	int port = 8080;
	int ret = 0;

	int timeout = 3;
	int connfd = -1;

	pthread_t pid;

	//1.服务器端，初始化；
	ret = sckServer_init(port, &listenfd);
	if (ret != 0)
	{
		printf("sckServer_init error: %d\n", ret);
		return ret;
	}

	while (1)
	{
		ret = sckServer_accept(listenfd, timeout, &connfd);
		if (ret == Sck_ErrTimeOut)
		{
			printf("------客户端连接超时------\n");
			continue;
		}
		else if (ret != 0)
		{
			printf("sckServer_accept error: %d\n", ret);
			return ret;
		}
		ret = pthread_create(&pid, NULL, start_routine, (void*)connfd);
	}

	//4.服务器端，环境释放；
	int sckServer_destroy();

	return 0;
}
*/